package com.magicsoft.share.presenter.share;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.share.ReportType;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.constant.SPKey;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.LoadingTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.utils.SPUtils;
import com.magicsoft.share.view.share.IReportView;

import java.util.List;

import io.reactivex.annotations.NonNull;

/**
 * Created by lyf on 2017/11/29/029.
 */

public class ReportPresenter extends BasePresenter<IReportView> {
    public void report(long targetId, long articleId, String reportType) {
        RetrofitUtil.getApi(APIService.class)
                .report(SPUtils.getInstance().getString(SPKey.TOKEN), SPUtils.getInstance().getLong(SPKey.ID),
                        targetId, articleId, reportType)
                .compose(new NetWorkTransformer())
                .compose(new LoadingTransformer(mContext))
                .subscribe(new SimpleObserver(mCompositeDisposable) {
                    @Override
                    public void call(@NonNull Object o) {

                        getView().reportSuccess();
                    }
                });
    }
    public void reportType() {
        RetrofitUtil.getApi(APIService.class)
                .reportTypeList(SPUtils.getInstance().getString(SPKey.TOKEN))
                .compose(new NetWorkTransformer<List<ReportType>>())
                .compose(new LoadingTransformer<List<ReportType>>(mContext))
                .subscribe(new SimpleObserver<List<ReportType>>(mCompositeDisposable) {
                    @Override
                    public void call(@NonNull List<ReportType> reportTypes) {
                        getView().reportTypeSuccess(reportTypes);
                    }


                });
    }
}
